package com.woniuxy;

import com.netflix.client.ClientException;
import com.woniuxy.entity.utils.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.net.ConnectException;
import java.net.Proxy;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: 马宇航
 * @Do: 统计出现问题的OpenFeign请求
 * @DateTime: 22/06/24/0024 上午 11:31
 * @Component: 成都蜗牛学苑
 **/
@RestControllerAdvice
public class Count {
    static AtomicInteger atomicInteger = new AtomicInteger(0);
    // 捕捉shiro的异常
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(ClientException.class)
    public ResponseEntity handle401(ClientException e) {
        int i = atomicInteger.incrementAndGet();
        System.out.println("openfeign调用超时，超时次数："+i);
        return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), null);
    }
}
